package cn.tedu.recruitmentwebsite.common.service;

import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Service
public class VerificationCodeService {

    private final Map<String, String> verificationCodes = new ConcurrentHashMap<>();

    public void saveVerificationCode(String phoneNumber, String code) {
        verificationCodes.put(phoneNumber, code);
    }

    public boolean verifyCode(String phoneNumber, String inputCode) {
        String storedCode = verificationCodes.get(phoneNumber);
        if (storedCode == null || !storedCode.equals(inputCode)) {
            return false;
        }
        verificationCodes.remove(phoneNumber); // 验证成功后移除验证码
        return true;
    }
}

